<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>流程设置代办人列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div align="left" class="btnsBox">
       <span id="sp_agent_usr_add_id" class="sq-button sq-button-hasicon"><i class="sqBtnIco_3"></i>新增</span>
    </div>
	<div id="ligergrid1" class="sq-grid"></div>
	<input hidden="true" id='manageId' name="manageId" value="${manageId }"/>
</div>

<script type="text/javascript">
	var grid = null;
	
	var dialogForAddMain =null;
    var dialogForChooseUsr =null;
    var _subWin=null;
	$(function () {
		initGrid();
		//新增代办人
        $("#sp_agent_usr_add_id").click(function(event) {
        	dialogForAddMain = $.ligerDialog.SQopen({
                width: 850,
                height:400,
                _data: {openDialogForChooseUsr: openDialogForChooseUsr},
                title : '设置代办人',
                url:'<%=path%>/flow/flow/toAddFlowAgentUsrPage.do',
                onClosed: function () {
                   //alert("从子窗口传参过来:"+"\n"+JSON.stringify(dialogForAddMain.get("_DATA")));  // _DATA是子窗口里传参给此dialog对象的
                },
                onLoaded: function () {
                    _subWin=dialogForAddMain.get("_subWin");
                }
            });
        });
	});
	
	//选择人的Dialog
	function openDialogForChooseUsr () {
		dialogForChooseUsr = $.ligerDialog.SQopen({
            url: "<%=path%>/flow/flow/toChooseUsrWinPage.do?isMore=0",
            width: 1000,
            title: "选择组织用户",
            onClosed: function () {
                //alert("从子窗口传参过来:"+"\n"+JSON.stringify(dialogForChooseUsr.get("_usrs")));  // _DATA是子窗口里传参给此dialog对象的
                dialogForAddMain.show();
                var usrs=dialogForChooseUsr.get("_usrs");
                set_selected_usrs(usrs);
            },
            onHideDialog: function () {
            	dialogForChooseUsr.close();
            }
        });
		dialogForAddMain.hide();
    }
	
	//弹出人员窗口设置人员
	function set_selected_usrs (usrs) {
        if (!usrs) return;
        dialogForAddMain.set("_usrs", usrs);
        var usrs_names=[];
        var usrs_ids=[];
        for (var i = 0; i < usrs.length; i++) {
            for(key in usrs[i]){
            	usrs_names.push(usrs[i][key]);
            	usrs_ids.push(key);
            }
        };
        _subWin.$("#agentUsrNm").val(usrs_names);
        _subWin.$("#agentUsrId").val(usrs_ids);
    }
	
	//初始化Grid
	function initGrid(){
		var manageId = $("#manageId").val();
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/flow/flow/initFlowAgentUsrList.do',
	    	method : 'get',
	        columns: [{
	                    display: '流程定义',
	                    name: 'processDefNm',
	                    minWidth: 100	
	                }, {
	                    display: '代办人',
	                    name: 'entrustUsrNm',
	                    minWidth: 100	
	                },{ 
	                	display: '开始时间', 
	                	name: 'startTm', 
	                	minWidth: 120 , 
	                	render:renderDate, 
	                	enabledSort:false
	                },{ display: '结束时间', 
	                	name: 'endTm', 
	                	minWidth: 120 , 
	                	render:renderDate, 
	                	enabledSort:false
	                },{
	                    display: '操作',
	                    width: 80,
	                    render: function (rowdata, rowindex, value) {
	                       var other='<a class="sq-button-hasicon" href="javascript:;" onclick="delAgentData(event';
		                       other+=",'"+rowdata.dataId+"'";
		                       other+=",'ligergrid1'";
		                       other+=")\"><i class=\"sqBtnIco_7\"></i>"+LogUtils.LOG_CMM_GRID_BTN_DELETE+"</a>";
	                        return other;
	                    }
	                } 
	        ],
	        usePager: true,
	        checkbox:true,
	        pageSize:100,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        //isScroll: false,
	        rownumbers:false/* ,
	        onRenderComplete: function () {
	        	iframeResize ();
	        } */
	    });
	    //赋值Grid
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	}
	
	//带条件重载Grid
	function reloadGrid(){
         grid.reload();
	}
	
	//删除代办人
	function delAgentData(event, _id, grid){
		var _url = '<%=path%>/flow/flow/removeFlowAgentUsr.do';
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			AjaxUtils.ajaxPost(_url, {id:_id}, function(msg){
				if(msg.success == 1){
					UIUtils.alertSuccess(msg.info);
   				 	reloadGrid();
	   			 }else{
	   				UIUtils.alertError(msg.info);
	   			 }
			},true);
		});
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	
	//清除按钮
	function clearBtn(){
		var form = new liger.get("searchBar");
		form.clear();
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
</script>
</body>
</html>